package com.wolf.etl.model;

import com.alibaba.fastjson.annotation.JSONField;
import com.wolf.exception.WolfException;
import com.wolf.provider.order.info.FieldInfo;
import com.wolf.provider.order.info.IdInfo;
import com.wolf.provider.order.info.TableInfo;
import org.springframework.util.StringUtils;

import java.util.Date;

/**
 * Created by tommy's father on 2017/8/17.
 */
@TableInfo(value = "etl_table")
public class EtlTableModel {

    @IdInfo
    private Long id;

    /**
     * 创建人
     */
    @FieldInfo(value = "creator")
    private String creator = "admin";

    /**
     * 创建时间
     */
    @FieldInfo(value = "create_time")
    private Date create_time = new Date();

    /**
     * 修改人
     */
    @JSONField(format="yyyy-MM-dd")//数据库导出页面时json格式化
    @FieldInfo(value = "modified_person")
    private String modified_person;

    /**
     * 修改时间
     */
    @JSONField(format="yyyy-MM-dd")//数据库导出页面时json格式化
    @FieldInfo(value = "modified_time")
    private Date modified_time;

    /**
     * 租户id
     */
    @FieldInfo(value = "client_id")
    private Long client_id = 100L;

    @FieldInfo(value = "etl_define_id")
    private Long etl_define_id;

    @FieldInfo(value = "data_source_id")
    private Long data_source_id;

    @FieldInfo(value = "name")
    private String name;

    @FieldInfo(value = "alias")
    private String alias;

    @FieldInfo(value = "primary_key")
    private String primary_key;

    @FieldInfo(value = "is_asc")
    private String is_asc;

    @FieldInfo(value = "remark")
    private String remark;

    @FieldInfo(value = "status")
    private int status;

    @FieldInfo(value = "is_master")
    private int is_master;

    @FieldInfo(value = "is_dynamic")
    private String is_dynamic;

    @FieldInfo(value = "catalog")
    private String catalog;

    @FieldInfo(value = "schema")
    private String schema;

    public String getCatalog() {
        return catalog;
    }

    public void setCatalog(String catalog) {
        this.catalog = catalog;
    }

    public String getSchema() {
        return schema;
    }

    public void setSchema(String schema) {
        this.schema = schema;
    }

    public Long getEtl_define_id() {
        return etl_define_id;
    }

    public void setEtl_define_id(Long etl_define_id) {
        this.etl_define_id = etl_define_id;
    }

    public Long getData_source_id() {
        return data_source_id;
    }

    public void setData_source_id(Long data_source_id) {
        this.data_source_id = data_source_id;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public String getAlias() {
        return alias;
    }

    public void setAlias(String alias) {
        this.alias = alias;
    }

    public String getPrimary_key() {
        return primary_key;
    }

    public void setPrimary_key(String primary_key) {
        this.primary_key = primary_key;
    }

    public String getIs_asc() {
        return is_asc;
    }

    public void setIs_asc(String is_asc) {
        this.is_asc = is_asc;
    }

    public String getRemark() {
        return remark;
    }

    public void setRemark(String remark) {
        this.remark = remark;
    }

    public int getStatus() {
        return status;
    }

    public void setStatus(int status) {
        this.status = status;
    }

    public int getIs_master() {
        return is_master;
    }

    public void setIs_master(int is_master) {
        this.is_master = is_master;
    }

    public String getIs_dynamic() {
        return is_dynamic;
    }

    public void setIs_dynamic(String is_dynamic) {
        this.is_dynamic = is_dynamic;
    }

    public void check() {
        if (StringUtils.isEmpty(this.getName())) {
            throw new WolfException(String.format("The ETL table[id=>%s] that it's name is empty.", this.getId()));
        }

        if (this.etl_define_id == 0L) {
            throw new WolfException(String.format("The ETL table[id=>%s] that it's etl define id is zero.", this.getId()));
        }
    }

    public Long getId() {
        return id;
    }

    public void setId(Long id) {
        this.id = id;
    }

    public String getCreator() {
        return creator;
    }

    public void setCreator(String creator) {
        this.creator = creator;
    }

    public Date getCreate_time() {
        return create_time;
    }

    public void setCreate_time(Date create_time) {
        this.create_time = create_time;
    }

    public String getModified_person() {
        return modified_person;
    }

    public void setModified_person(String modified_person) {
        this.modified_person = modified_person;
    }

    public Date getModified_time() {
        return modified_time;
    }

    public void setModified_time(Date modified_time) {
        this.modified_time = modified_time;
    }

    public Long getClient_id() {
        return client_id;
    }

    public void setClient_id(Long client_id) {
        this.client_id = client_id;
    }
}
